Skip to content

feat(theme): add initial i18n support#1210

Merged
sserrata merged 3 commits into
PaloAltoNetworks:mainfrom
sserrata:codex/review-issue-#1146-and-recommend-plan
Aug 25, 2025
Merged

feat(theme): add initial i18n support#1210
sserrata merged 3 commits into
PaloAltoNetworks:mainfrom
sserrata:codex/review-issue-#1146-and-recommend-plan

Conversation

@sserrata

@sserrata sserrata commented Jul 17, 2025

Copy link
Copy Markdown
Member

Summary

  • add translation id constants

Covered components:

  • ApiTabs
  • ApiExplorer/Authorization
  • ApiExplorer/Body
  • ApiExplorer/FormFileUpload
  • ApiExplorer/FormItem
  • ApiExplorer/FormTextInput
  • ApiExplorer/LiveEditor
  • ApiExplorer/ParamOptions along with its form item variants (ParamArrayFormItem, ParamBooleanFormItem, ParamMultiSelectFormItem, ParamSelectFormItem)
  • ApiExplorer/Request
  • ApiExplorer/Response
  • ApiExplorer/SecuritySchemes
  • ApiExplorer/Server
  • ParamsDetails
  • ParamsItem
  • RequestSchema
  • ResponseExamples
  • ResponseSchema
  • SchemaItem
  • StatusCodes

Addresses #1146 and #319

Testing

  • yarn lint
  • yarn test

https://chatgpt.com/codex/tasks/task_e_6865400bebe483238103ef34d718fea3

@sserrata sserrata self-assigned this Jul 17, 2025
@sserrata sserrata added the enhancement New feature or request label Jul 17, 2025
@github-actions

github-actions Bot commented Jul 17, 2025

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit bff2fc7):

https://docusaurus-openapi-36b86--pr1210-b3lsuhbz.web.app

(expires Sat, 16 Aug 2025 17:56:45 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@sserrata sserrata added the reviewing 👀 Undergoing manual audit to determine if issue should still be active label Aug 1, 2025
@sserrata sserrata merged commit 02a29ef into PaloAltoNetworks:main Aug 25, 2025
11 checks passed
dsuket pushed a commit to dsuket/docusaurus-openapi-docs that referenced this pull request Oct 13, 2025
* feat(theme): add initial i18n support

* Add i18n wrappers across more theme components

* localize remaining theme components
@navrocky

navrocky commented Jun 9, 2026

Copy link
Copy Markdown

i18n strings are not extracted by write-translations

The runtime side of this PR works: components call translate({ id, message }) / <Translate id={...}> with sensible English message defaults, so the UI renders correctly, and if you manually add the keys to a locale's code.json, the translated strings do show up at runtime. The lookup works because the imported constant (e.g. OPENAPI_REQUEST.COLLAPSE_ALL) is inlined to its literal string value at build time, so the runtime id matches the
code.json key.

The problem is static extraction. Running docusaurus write-translations does not pick up any of these strings, so there's no generated template for translators to fill in.

Root cause: every translate()/<Translate> call passes the id as an imported constant reference instead of a string literal:

import { OPENAPI_REQUEST } from "@theme/translationIds";

translate({ id: OPENAPI_REQUEST.COLLAPSE_ALL, message: "Collapse all" });
//             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ member expression on a cross-module binding

Docusaurus extracts code translations via Babel in @docusaurus/babel/lib/babelTranslationsExtractor.js. For translate() it does:

const firstArgEvaluated = firstArgPath.evaluate();
if (firstArgEvaluated.confident && isObject(firstArgEvaluated.value)) {
  const { message, id, description } = firstArgEvaluated.value;
  translations[String(id ?? message)] = { message: String(message ?? id), description };
} else {
  warnings.push(`translate() first arg should be a statically evaluable object. ...`);
}

Babel's path.evaluate() cannot resolve a member expression on a binding imported from another module (@theme/translationIds), so confident === false.

The whole argument is skipped and a warning is logged — nothing lands in code.json. The same applies to the <Translate id={OPENAPI_*.X}> JSX form, since the id prop is also a non-literal expression.

Fix: the id (and ideally description) must be string literals at the call site for extraction to work, e.g.:

translate({
  id: "theme.openapi.request.collapseAll",
  message: "Collapse all",
  description: "Label for the collapse-all button in the API request panel",
});

The translationIds.ts constants can stay as a reference/source-of-truth, but they can't be used as the id argument if write-translations is expected to extract them.

Separately, worth noting for users: these are theme code translations, so overrides belong in i18n//code.json — not in i18n//docusaurus-plugin-content-docs-api/current.json (which only holds docs-plugin content translations like version.label). Putting theme.openapi.* keys in the latter has no effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request reviewing 👀 Undergoing manual audit to determine if issue should still be active

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants